<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 运单信息
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column prop="type" label="设备类型"></el-table-column>
                <el-table-column prop="gname" label="货物类型"></el-table-column>
                <el-table-column prop="start_time" label="发货时间" width="250px"></el-table-column>
                <el-table-column label="收货时间" width="250px">
                    <template slot-scope="scope">{{scope.row.end_time | active}}</template>
                </el-table-column>
                <el-table-column label="运单状态">
                    <template slot-scope="scope">{{scope.row.status | active_status}}</template>
                </el-table-column>
                <el-table-column label="报警状态">
                    <template slot-scope="scope">{{scope.row.is_alert | active_alert}}</template>
                </el-table-column>
                <el-table-column prop="gap" label="上报间隔" width="100px"></el-table-column>

                <el-table-column prop="contacts" label="联系人名称"></el-table-column>
                <el-table-column prop="phone" label="联系人电话"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit(scope.$index,scope.row)"
                        >查看温度数据</el-button>
                        <el-button
                            type="text"
                            icon="el-icon-present"
                            class="red"
                            @click="handleDelete(scope.$index, scope.row)"
                        >收货</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="查看" :visible.sync="editVisible" width="40%">
            <el-form ref="form" :model="form" label-width="100px">
                <!-- <el-form-item label="温度数据">
                    <el-input v-model="form.temp" style="width: 50%;"></el-input>
                </el-form-item> -->
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>温度数据</span>
                    </div>
                    <div class="text item">
                        {{form.temp}}
                    </div>
                </el-card>
            </el-form>
            <div class="schart-box">
                <schart class="schart" canvasId="line" :options="options2"></schart>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { getorder_id,updateorder } from '../../api/api';
import Schart from 'vue-schart';
export default {
    name: 'showorder',
    data() {
        return {
            query: {
                address: '',
                name: '',
                pageIndex: 1,
                pageSize: 10
            },
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1,
            options2: {
                type: 'line',
                title: {
                    text: '运单运输过程温度折线图'
                },
                bgColor: '#fbfbfb',
                labels: ['运输过程中'],
                datasets: [
                    {
                        label: '家电',
                        data: [234, 278, 270, 190, 230]
                    },
                ]
            },
            form: {
                cus_com: '',//客户名称
                phone:'',
                address:'',
                contacts:'',//联系人
                temperature:"",
                temp:'',
            }
        };
    },
    components: {
        Schart
    },
    created() {
        this.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        getData() {
            getorder_id().then(res => {
                this.tableData = res.orderdata;
            });
        },
        // 删除操作
        handleDelete(index, row) {
            var params = {
                order_id:row.id,
                gap:row.gap,
                temperature:row.temperature,
            }
            // console.log(params)
            updateorder(params).then(res=>{
                this.$message.success(res.message)
            })
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        delAllSelection() {
            const length = this.multipleSelection.length;
            let str = '';
            this.delList = this.delList.concat(this.multipleSelection);
            for (let i = 0; i < length; i++) {
                str += this.multipleSelection[i].name + ' ';
            }
            this.$message.error(`删除了${str}`);
            this.multipleSelection = [];
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.form = row;
            var id = row.id;
            // console.log(id)
            this.$router.push({path:'showorderinfo',query:{"id":id}})
            // this.editVisible = true;
        },
        // 保存编辑
        saveEdit() {
            var params={
                id:this.idx,
                cus_com:this.form.cus_com,//客户名称
                phone:this.form.phone,
                address:this.form.address,
                contacts:this.form.contacts,//联系人
            }
            updatecustomer(params).then(res=>{
                this.$message.success(res.message);
            })
            this.editVisible = false;
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    },
    filters:{
        active(val){
            if (val) {
                return val
            }else{
                return '暂无'
            }
        },
        active_status(val){
            if (val>0) {
                return '完成'
            }else{
                return '在途'
            }
        },
        active_alert(val){
            if (val>0) {
                return '报警'
            }else{
                return '正常'
            }
        },
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
.schart-box {
    display: inline-block;
    margin: 20px;
}
.schart {
    width: 600px;
    height: 400px;
}
</style>
